﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Grishko.DataTier;

namespace OutdoorLib.BaseEntity.Agency
{
    public class Price : EntitySingle
    {
        private int  _value = 0;
        public int Value { get { return _value; } set { _value = value; } }

        private DateTime _DateValue = DateTime.Now;
        public DateTime DateValue { get { return _DateValue; } set { _DateValue = value; } }
    }

    public class PriceList : EntityList
    {
        //public int PriceValue
        //{
        //    get { return GetCurrentPrice(); }
        //    set { ; }
        //}

        public Price[] GetSortList()
        { 
             SortPriceList comp= new SortPriceList ();
            Price[] pr= this.ToArray <Price >();
            Array.Sort(pr, comp);
            return pr;
        }

        protected class SortPriceList:System.Collections.IComparer   
        {
            #region IComparer Members

            public int Compare(object x, object y)
            {                
                if (((Price)y).DateValue < ((Price)x).DateValue) return -1;
                if (((Price)y).DateValue > ((Price)x).DateValue) return 1;
                return 0;
            }

            #endregion
        }

        public int GetCurrentPrice()
        {
            foreach (Price item in GetSortList())
            {
                return item.Value; 
            }
            return 0;
        }

        public int GetCurrentPriceForDate(DateTime Date )
        {
            return GetCurrentPrice();
        }
        
        
    }

    

}
